package com.ruoyi.system.service.impl;

import java.util.Collections;
import java.util.List;

import com.ruoyi.system.domain.EmployeeAssessmentDetail;
import com.ruoyi.system.domain.EmployeeIndicatorScore;
import com.ruoyi.system.domain.MidPlanAssess;
import com.ruoyi.system.mapper.EmployeeAssessmentDetailMapper;
import com.ruoyi.system.mapper.EmployeeIndicatorScoreMapper;
import com.ruoyi.system.mapper.MidPlanAssessMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.AssessmentPlanMapper;
import com.ruoyi.system.domain.AssessmentPlan;
import com.ruoyi.system.service.IAssessmentPlanService;

/**
 * 员工考核计划----DmyService业务层处理
 * 
 * @author dmy
 * @date 2025-05-30
 */
@Service
public class AssessmentPlanServiceImpl implements IAssessmentPlanService 
{
    @Autowired
    private AssessmentPlanMapper assessmentPlanMapper;

    /**
     * 查询员工考核计划----Dmy
     * 
     * @param id 员工考核计划----Dmy主键
     * @return 员工考核计划----Dmy
     */
    @Override
    public AssessmentPlan selectAssessmentPlanById(Long id)
    {
        return assessmentPlanMapper.selectAssessmentPlanById(id);
    }

    /**
     * 查询员工考核计划----Dmy列表
     * 
     * @param assessmentPlan 员工考核计划----Dmy
     * @return 员工考核计划----Dmy
     */
    @Override
    public List<AssessmentPlan> selectAssessmentPlanList(AssessmentPlan assessmentPlan)
    {
        return assessmentPlanMapper.selectAssessmentPlanList(assessmentPlan);
    }

    /**
     * 新增员工考核计划----Dmy
     * 
     * @param assessmentPlan 员工考核计划----Dmy
     * @return 结果
     */
    @Override
    public int insertAssessmentPlan(AssessmentPlan assessmentPlan)
    {
        assessmentPlan.setDelFlag(0l);
        assessmentPlanMapper.insertAssessmentPlan(assessmentPlan);
        Long generatedId = assessmentPlan.getId(); // 插入后自动获取自增ID
        return generatedId.intValue();
    }

    /**
     * 修改员工考核计划----Dmy
     * 
     * @param assessmentPlan 员工考核计划----Dmy
     * @return 结果
     */
    @Override
    public int updateAssessmentPlan(AssessmentPlan assessmentPlan)
    {
        return assessmentPlanMapper.updateAssessmentPlan(assessmentPlan);
    }

    /**
     * 批量删除员工考核计划----Dmy
     * 
     * @param ids 需要删除的员工考核计划----Dmy主键
     * @return 结果
     */
    @Override
    public int deleteAssessmentPlanByIds(Long[] ids)
    {
        return assessmentPlanMapper.deleteAssessmentPlanByIds(ids);
    }

    /**
     * 删除员工考核计划----Dmy信息
     * 
     * @param id 员工考核计划----Dmy主键
     * @return 结果
     */
    @Override
    public int deleteAssessmentPlanById(Long id)
    {
        return assessmentPlanMapper.deleteAssessmentPlanById(id);
    }

    @Override
    public List<Integer> selectALLEmployeeIdByAssessmentPlanId(Integer id) {
        return assessmentPlanMapper.selectALLEmployeeIdByAssessmentPlanId(id);
    }

    @Override
    public List<Integer> selectALLIndicatorsIdByAssessmentPlanId(Integer id) {
        return assessmentPlanMapper.selectALLIndicatorsIdByAssessmentPlanId(id);
    }
    @Autowired
    private EmployeeAssessmentDetailMapper employeeAssessmentDetailMapper;

    //添加插入员工id和考核计划id
    @Override
    public Integer add(Integer employeeId, Integer planId) {
        EmployeeAssessmentDetail employeeAssessmentDetail = new EmployeeAssessmentDetail();
        employeeAssessmentDetail.setEmployeeId(employeeId);
        employeeAssessmentDetail.setAssessmentPlanId(planId);
        employeeAssessmentDetail.setAssessmentStatus("待评分");
        int i = employeeAssessmentDetailMapper.insert(employeeAssessmentDetail);
        return i;
    }
    @Autowired
    private EmployeeIndicatorScoreMapper employeeIndicatorScoreMapper;

    //添加员工指标id和考核计划id
    @Override
    public Integer addEmployeeIndicator(Integer employeeId, Integer indicatorsId) {
        EmployeeIndicatorScore employeeIndicatorScore = new EmployeeIndicatorScore();
        employeeIndicatorScore.setEmployeeId(employeeId);
        employeeIndicatorScore.setIndicatorId(indicatorsId);
        int i = employeeIndicatorScoreMapper.insert(employeeIndicatorScore);
        return i;
    }

    @Override
    public Integer deleteEmployeeAssessmentDetailByEmployeeId(Integer employeeId) {
        return employeeAssessmentDetailMapper.deleteByEmployeeId(employeeId);
    }

    @Override
    public Integer deleteEmployeeIndicatorScoreByEmployeeId(Integer employeeId) {
        return employeeIndicatorScoreMapper.deleteByEmployeeId(employeeId);
    }
}
